package com.eorchis.module.classcourse.service.impl;

import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.apache.commons.fileupload.FileItem;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.eorchis.core.basedao.dao.IDaoSupport;
import com.eorchis.core.basedao.entity.IBaseEntity;
import com.eorchis.core.service.impl.AbstractBaseService;
import com.eorchis.module.basedata.domain.BaseData;
import com.eorchis.module.basedata.domain.BaseDataCondition;
import com.eorchis.module.basedata.manager.IBaseDataManager;
import com.eorchis.module.basedata.service.cache.BaseDataCacheUtil;
import com.eorchis.module.classcourse.dao.IClassCourseDao;
import com.eorchis.module.classcourse.domain.ClassCourse;
import com.eorchis.module.classcourse.querybean.ClassCourseQueryBean;
import com.eorchis.module.classcourse.service.IClassCourseService;
import com.eorchis.module.classcourse.ui.commond.ClassCourseQueryCommond;
import com.eorchis.module.classcourse.ui.commond.ClassCourseValidCommond;
import com.eorchis.module.exceluitls.domain.excel.ExcelCell;
import com.eorchis.module.trainingclass.domain.TrainingClass;
import com.eorchis.module.trainingclass.service.ITrainingClassService;
import com.eorchis.utils.utils.PropertyUtil;

/**
 * Title: ClassCourseServiceImpl<br>
 * Description: 班级课程维护管理业务接口实现<br>
 * Company: GoldGov<br>
 * Copyright @ 2012 GoldGov .All rights reserved.<br>
 * @author Max
 * @createDate 2014-12-11
 * @version $Revision$
 */
// 声明本类为Server实现类，声明bean名称
@Service(value = "com.eorchis.module.classcourse.service.impl.ClassCourseServiceImpl")
public class ClassCourseServiceImpl 
			extends AbstractBaseService 
		implements IClassCourseService {
		
	@Autowired
	@Qualifier("com.eorchis.module.classcourse.dao.impl.ClassCourseDaoImpl")
	private IClassCourseDao classCourseDao;
	@Autowired
	@Qualifier("com.eorchis.module.basedata.manager.impl.BaseDataManagerImpl")
	private IBaseDataManager baseDataManager;
	@Resource(name = "com.eorchis.module.basedata.service.cache.BaseDataCacheUtil")
	private BaseDataCacheUtil baseDataCacheUtil;
	
	@Autowired
	@Qualifier("com.eorchis.module.trainingclass.service.impl.TrainingClassServiceImpl")
	private ITrainingClassService trainingClassService;
	
	private static Object o=new Object();

	public IDaoSupport getDaoSupport() {
		return classCourseDao;
	}
	@SuppressWarnings("unchecked")
	public ClassCourseValidCommond toCommond(IBaseEntity entity) {
		return new ClassCourseValidCommond((ClassCourse)entity);
	}

	/**
	 * 查询班级课程列表
	 * @param commond
	 * @return
	 * @throws Exception
	 * @author Max
	 * @date 2014-12-11
	 */
	@Override
	public List<ClassCourseQueryBean> findClassCourseAllList(ClassCourseQueryCommond 
			qCommond) throws Exception {
		return classCourseDao.findClassCourseAllList(qCommond);
	}
	
	/**
	 * 查询班级课程列表
	 * @param commond
	 * @return
	 * @throws Exception
	 * @author Max
	 * @date 2014-12-11
	 */
	@Override
	public List<ClassCourseQueryBean> findClassCoursePageList(ClassCourseQueryCommond 
			qCommond) throws Exception {
		return classCourseDao.findClassCoursePageList(qCommond);
	}
	
	/**
	 * 修改班级信息
	 * @param commond
	 * @return
	 * @throws Exception
	 * @author Max
	 * @date 2014-12-11
	 */
	
	@Override
	public void updateCourse(ClassCourseValidCommond vCommond) throws Exception{
		ClassCourseValidCommond entityCommond = this.find(vCommond.getClassCourseId());
		//Double oldScore=entityCommond.getStudyScore();
		entityCommond.setCourseName(vCommond.getCourseName());
		entityCommond.setSpeaker(vCommond.getSpeaker());
		entityCommond.setSpeakdept(vCommond.getSpeakdept());
		entityCommond.setSpeakDuty(vCommond.getSpeakDuty());
		//entityCommond.setCourseNum(vCommond.getCourseNum());
		//entityCommond.setStudyScore(vCommond.getStudyScore());
		//entityCommond.setDutyRemark(vCommond.getDutyRemark());
		//entityCommond.setContent(vCommond.getContent());
		if(vCommond.getSpeakway()!=null) {
			Map<String, BaseData> baseDataMap =  baseDataCacheUtil.getBaseData();
			BaseData b=baseDataMap.get(vCommond.getSpeakway());
			ClassCourse course=(ClassCourse) entityCommond.toEntity();
			course.setSpeakway(b);
		}else {
			entityCommond.setSpeakway(null);
		}
		if(vCommond.getSpeakTime()!=null) {
			Map<String, BaseData> baseDataMap =  baseDataCacheUtil.getBaseData();
			BaseData b=baseDataMap.get(vCommond.getSpeakTime());
			ClassCourse course=(ClassCourse) entityCommond.toEntity();
			course.setSpeakTime(b);
		}else {
			entityCommond.setSpeakTime(null);
		}
		if(PropertyUtil.objectNotEmpty(vCommond.getSpeakDateStr())){
			ClassCourse course=(ClassCourse) entityCommond.toEntity();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			course.setSpeakDate(sdf.parse(vCommond.getSpeakDateStr()));
		}
		/*//修改学时操作
		ClassCourse courseInfo=(ClassCourse) entityCommond.toEntity();
		TrainingClass tclass=courseInfo.getTrainingClass();
		tclass.getTrainingHour();
		Double hour=tclass.getTrainingHour()-oldScore+vCommond.getStudyScore();//最后的学时
		trainingClassService.updateStudyHour(hour, tclass.getClassId());
		if(tclass.getAuditState().equals(TrainingClass.IS_AUDIT_N)) {
			trainingClassService.updateCState(tclass.getClassId());
		}
		//修改学时操作*/
		this.update(entityCommond);
	}
	
	/**
	 * 查询班级课程列表数量
	 * @param commond
	 * @return
	 * @throws Exception
	 * @author Max
	 * @date 2014-12-11
	 */
	@Override
	public List<ClassCourseQueryBean> findCourseNum(ClassCourseQueryCommond 
			qCommond) throws Exception {
		return classCourseDao.findCourseNum(qCommond);
	}
	
	/**
	 * 获取这一年中培训班课程最大的编号
	 * @throws Exception
	 * @author Max
	 * @createDate 2014-12-12
	 */
	@Override
	public String getMaxCourseNum(ClassCourseValidCommond vCommond) throws Exception{
		String result=classCourseDao.getMaxCourseNum(vCommond);
		if(result.equals("empty")) {
			return vCommond.getSearchCourseNum()+"001";
		}else {
			int re=Integer.parseInt(result);
			Integer num=re+1;
			return num+"";
		}
	}
	
	/**
	 * 获取课程中的学时总数
	 * @throws Exception
	 * @author Max
	 * @createDate 2014-12-12
	 */
	@Override
	public Double getstudyScore(String [] ids) throws Exception{
		return classCourseDao.getstudyScore(ids);
	}
	
	/**
	 * 导入课程
	 * @throws Exception
	 * @author Max
	 * @createDate 2014-12-12
	 *//*
	@Override
	public String importCourseForExcel(ClassCourseValidCommond vCommond,ExcelSheet sheet) throws Exception{
		synchronized(o) {			
			Map<String,List<BaseData>> baseDataMap =  baseDataCacheUtil.getBaseDataList();
			List<BaseData>  baseDataList = baseDataMap.get("skfs");//课程类型
			List<BaseData>  baseDataList2 = baseDataMap.get("speakTime");//授课时间
			//获取最大编号
			TrainingClassValidCommond co=trainingClassService.find(vCommond.getClassId());
			TrainingClass tc=(TrainingClass) co.toEntity();
			vCommond.setSearchCourseNum(tc.getClassNum());
			Integer bianhao=Integer.parseInt(this.getMaxCourseNum(vCommond));//最大编号
			//获取最大编号
			//String msg="";
			StringBuffer msg=new StringBuffer();
			List<ExcelRow> eRows=sheet.getRowList();
			//判断excel的表头对不对
			boolean state=false;
			try {
				ExcelRow topRow=eRows.get(0);
				List<ExcelCell> topRowCells =topRow.getCellList();
//				if(topRowCells.size()>7) {
//					state=true;
//				}
				if(topRowCells.get(0).getCellValue()==null||topRowCells.get(0).getCellValue().toString().trim().length()==0||!topRowCells.get(0).getCellValue().toString().trim().equals("日期")) {
					state=true;
				}
				if(topRowCells.get(1).getCellValue()==null||topRowCells.get(1).getCellValue().toString().trim().length()==0||!topRowCells.get(1).getCellValue().toString().trim().equals("上午/下午")) {
					state=true;
				}
				if(topRowCells.get(2).getCellValue()==null||topRowCells.get(2).getCellValue().toString().trim().length()==0||!topRowCells.get(2).getCellValue().toString().trim().equals("课程名")) {
					state=true;
				}
				if(topRowCells.get(3).getCellValue()==null||topRowCells.get(3).getCellValue().toString().trim().length()==0||!topRowCells.get(3).getCellValue().toString().trim().equals("课程类型")) {
					state=true;
				}
				if(topRowCells.get(4).getCellValue()==null||topRowCells.get(4).getCellValue().toString().trim().length()==0||!topRowCells.get(4).getCellValue().toString().trim().equals("授课教师")) {
					state=true;
				}
				if(topRowCells.get(5).getCellValue()==null||topRowCells.get(5).getCellValue().toString().trim().length()==0||!topRowCells.get(5).getCellValue().toString().trim().equals("教师单位")) {
					state=true;
				}
				if(topRowCells.get(6).getCellValue()==null||topRowCells.get(6).getCellValue().toString().trim().length()==0||!topRowCells.get(6).getCellValue().toString().trim().equals("教师职务职称")) {
					state=true;
				}
				if(state) {
					msg.append("您使用的导入模板不正确，请确认后重新导入。<br/>");
					return msg.toString();
				}
			}catch(Exception e) {
				msg.append("您使用的导入模板不正确，请确认后重新导入。");
				return msg.toString();
			}
			//判断excel的表头对不对 
			List<ClassCourseValidCommond> list=new ArrayList<ClassCourseValidCommond>();
			for(int i=1;i<eRows.size();i++){
				ExcelRow eRow=eRows.get(i);
				if(i>1) {
					bianhao=bianhao+1;
				}
				try {
					List<ExcelCell> eCells =eRow.getCellList();
					//开始获取单元格的值
					ClassCourseValidCommond courseCvommond=new ClassCourseValidCommond();
					//判断是否是空行  如果都为空不做处理
					boolean nullNum=judgeNullRow(eCells,7);
					if(nullNum) {
						continue;
					}
					//判断是否是空行 
					//第一列为日期
					if(eCells.get(0).getDateValue()==null||eCells.get(0).getDateValue().toString().trim().length()==0) {
						msg.append("第" + eRow.getRowNum() + "行 \"日期\" " + "列不能为空，请修改后重新导入。<br/>");
					}else{//验证日期格式是否正确
						//判断日期格式
						boolean isSpeakDate = isDate(eCells.get(0).getDateValue().toString().trim());
						if(isSpeakDate){
							courseCvommond.setSpeakDateStr(eCells.get(0).getDateValue().toString().trim());
						}else{
							msg.append("第" + eRow.getRowNum() + "行 \"日期\" " + "列输入有误，应输入正确的日期，请修改后重新导入。<br/>") ;
						}
					}
					//第二列为上午/下午
					if(eCells.get(1).getCellValue()==null||eCells.get(1).getCellValue().toString().trim().length()==0) {
						msg.append("第" + eRow.getRowNum() + "行 \"上午/下午\" " + "列不能为空，请修改后重新导入。<br/>") ;
					}
					ClassCourse course=(ClassCourse) courseCvommond.toEntity();
					for(int j=0;j<baseDataList2.size();j++) {
						BaseData basedata=baseDataList2.get(j);
						if(eCells.get(1).getCellValue().toString().equals(basedata.getDataName())) {
							course.setSpeakTime(basedata);
						}
					}
					if(course.getSpeakTime()==null) {
						msg.append("第" + eRow.getRowNum() + "行 \"上午/下午\" " + "列输入有误，应输入正确数据，请修改后重新导入。<br/>") ;
					}
					
					//第三列为课程名
					if(eCells.get(2).getCellValue()==null||eCells.get(2).getCellValue().toString().trim().length()==0) {
						msg.append("第" + eRow.getRowNum() + "行 \"课程名\" " + "列不能为空，请修改后重新导入。<br/>");
					}
					if(eCells.get(2).getCellValue()!=null&&eCells.get(2).getCellValue().toString().trim().length()>30) {
						msg.append("第" + eRow.getRowNum() + "行 \"课程名\" " + "列输入字数超过了30字，请修改后重新导入。<br/>") ;
					}
					courseCvommond.setCourseName(eCells.get(2).getCellValue()+"");
					//第四列为课程类型
					if(eCells.get(3).getCellValue()==null||eCells.get(3).getCellValue().toString().trim().length()==0) {
						//msg = "第" + eRow.getRowNum() + "行记录导入出错!" + "错误原因:授课方式不能为空!" ;
						msg.append("第" + eRow.getRowNum() + "行 \"课程类型\" " + "列不能为空，请修改后重新导入。<br/>") ;
					}
					//ClassCourse course=(ClassCourse) courseCvommond.toEntity();
					for(int j=0;j<baseDataList.size();j++) {
						BaseData basedata=baseDataList.get(j);
						if(eCells.get(3).getCellValue().toString().equals(basedata.getDataName())) {
							course.setSpeakway(basedata);
						}
					}
					if(course.getSpeakway()==null) {
						msg.append("第" + eRow.getRowNum() + "行 \"课程类型\" " + "列输入有误，应输入系统指定的课程类型，请修改后重新导入。<br/>") ;
					}
					 //第五列为授课教师
					if(eCells.get(4).getCellValue()==null||eCells.get(4).getCellValue().toString().trim().length()==0) {
						msg.append("第" + eRow.getRowNum() + "行 \"授课教师\" " + "列不能为空，请修改后重新导入。<br/>") ;
					}
					if(eCells.get(4).getCellValue()!=null&&eCells.get(4).getCellValue().toString().trim().length()>20) {
						msg.append("第" + eRow.getRowNum() + "行 \"授课教师\" " + "列输入字数超过了20字，请修改后重新导入。<br/>") ;
					}
					courseCvommond.setSpeaker(eCells.get(4).getCellValue()+"");
					//第六列为教师单位
					if(eCells.get(5).getCellValue()==null||eCells.get(5).getCellValue().toString().trim().length()==0) {
						msg.append("第" + eRow.getRowNum() + "行 \"教师单位\" " + "列不能为空，请修改后重新导入。<br/>") ;
					}
					if(eCells.get(5).getCellValue()!=null&&eCells.get(5).getCellValue().toString().trim().length()>30) {
						msg.append("第" + eRow.getRowNum() + "行 \"教师单位\" " + "列输入字数超过了50字，请修改后重新导入。<br/>") ;
						
					}
					courseCvommond.setSpeakdept(eCells.get(5).getCellValue()+"");
					//第七列为讲师职务
					if(eCells.get(6).getCellValue()==null||eCells.get(6).getCellValue().toString().trim().length()==0) {
						msg.append("第" + eRow.getRowNum() + "行 \"教师职称/职务\" " + "列不能为空，请修改后重新导入。<br/>") ;
					}
					if(eCells.get(6).getCellValue()!=null&&eCells.get(6).getCellValue().toString().trim().length()>50) {
						msg.append("第" + eRow.getRowNum() + "行 \"教师职称/职务\" " + "列输入字数超过了30字，请修改后重新导入。<br/>") ;
					}
					courseCvommond.setSpeakDuty(eCells.get(6).getCellValue()+"");
					//其它属性
					courseCvommond.setCourseNum(bianhao.toString());
					course.setTrainingClass(tc);
					course.setCreateDate(new Date());
					list.add(courseCvommond);
				}catch (Exception e){
					msg.append("您使用的导入模板不正确，请确认后重新导入。<br/>");
				}
			}
			if(!msg.toString().equals("")) {
				return msg.toString();
			}
			//执行添加
			//修改学时
			if(list!=null&&list.size()>0) {
				for(int i=0;i<list.size();i++) {
					ClassCourseValidCommond c=list.get(i);
					this.save(c);
				}
			}			
			return msg.toString();
		}
	}*/
	
	/**
	 * 导入课程
	 * @throws Exception
	 * @author Max
	 * @createDate 2014-12-12
	 */
	@Override
	public String importCourseForExcel(ClassCourseValidCommond vCommond,FileItem file, 
			HttpServletResponse response, HttpServletRequest request) throws Exception{
		InputStream inputStream;
		POIFSFileSystem fs;
		HSSFWorkbook wb;
		int rowNum = 0;
		String resultStr="";
		TrainingClass trainingClass=new TrainingClass();
		trainingClass.setClassId(vCommond.getClassId());
		List<ClassCourseValidCommond> list=new ArrayList<ClassCourseValidCommond>();
		//实例化格式不正确的的集合
		List<ClassCourseValidCommond> errorCoueseList = new ArrayList<ClassCourseValidCommond>();
		//结果集
		ClassCourseValidCommond classCourseValid=null;
		try {
			inputStream = file.getInputStream();
			fs = new POIFSFileSystem(inputStream);
			wb = new HSSFWorkbook(fs);
			HSSFSheet sheet = wb.getSheetAt(0);
			for (Row row : sheet) {
				rowNum = row.getRowNum();
				if (rowNum > 0) {
					ClassCourseValidCommond courseCvommond=new ClassCourseValidCommond();
					courseCvommond = convertCelltoCourse(row, courseCvommond);
					if(!PropertyUtil.objectNotEmpty(courseCvommond) || !(courseCvommond.getImportFlag())){
						//不正确的课程
						if(courseCvommond!=null){
							courseCvommond.setRow(row.getRowNum()+1);
							errorCoueseList.add(courseCvommond);
						}
					}else{
						classCourseValid=this.validateUserInfo(courseCvommond);
						if(PropertyUtil.objectNotEmpty(classCourseValid) && classCourseValid.getImportFlag()){
							ClassCourse course= (ClassCourse) courseCvommond.toEntity();
							//添加班级对象
							course.setTrainingClass(trainingClass);
							//添加课程类型
							BaseData ba=new BaseData();
							ba.setDataCode(courseCvommond.getSpeakway());
							course.setSpeakway(ba);
							//添加授课时间
							BaseData bd=new BaseData();
							bd.setDataCode(courseCvommond.getSpeakTime());
							course.setSpeakTime(bd);
							//添加创建时间GUOLEI   
							courseCvommond.setCreateDate(new Date());
							list.add(courseCvommond);
						}else{
							//不正确的课程
							courseCvommond.setRow(row.getRowNum()+1);
							errorCoueseList.add(courseCvommond);
						}
					}
				}
			}
			//执行添加
			if(list!=null&&list.size()>0) {
				for(int i=0;i<list.size();i++) {
					ClassCourseValidCommond c=list.get(i);
					this.save(c);
				}
			}
			
			if(PropertyUtil.objectNotEmpty(errorCoueseList)){
				for(ClassCourseValidCommond es : errorCoueseList){
					resultStr+="行号为"+es.getRow()+"的课程"+es.getReason()+"\r\n";
					
				}
			}else{
				resultStr = "导入成功";
			}
		}catch (IOException e) {
			e.printStackTrace();
			resultStr = "failure";
			throw e;
		}
		return resultStr;
		
	}
	
	/*
	 * 判断这一行是否为空
	 */
	private boolean judgeNullRow(List<ExcelCell> eCells,int column) {
		int sumNum=0;
		if(eCells.size()<column) {
			column=eCells.size();
		}
		for(int i=0;i<column;i++) {
			if(eCells.get(i).getCellValue()==null||eCells.get(i).getCellValue().toString().trim().length()==0) {
				sumNum=sumNum+1;
			}
		}
		if(sumNum==column) {
			return true;
		}
		
		return false;
	}
	/**
	 * 将Excel一行数据转换为course对象
	 * @param row
	 * @param course
	 * @return course
	 * @throws Exception 
	 */
	private ClassCourseValidCommond convertCelltoCourse(Row row, ClassCourseValidCommond courseCvommond) throws Exception {
		SimpleDateFormat sf3 = new SimpleDateFormat("yyyy-MM-dd");
		int columnIndex = 0;
		Boolean importFlag = true;
		String reason = "";
		boolean empty = true;
		courseCvommond = new ClassCourseValidCommond();
		if(PropertyUtil.objectNotEmpty(row)){
			for (Cell cell : row) {
				columnIndex = cell.getColumnIndex();
				if (!PropertyUtil.objectNotEmpty(getValue(cell)))
					continue;
				empty = false;
				switch (columnIndex) {
					case 0 ://日期
						try{
							if (PropertyUtil.objectNotEmpty(getValue(cell))) {
								if (Cell.CELL_TYPE_NUMERIC == cell.getCellType()) {
									if (DateUtil.isCellDateFormatted(cell))
										courseCvommond.setSpeakDateStr("".equals(getValue(cell)) ? null : sf3.format((Date) getValue(cell)));
								} else {
									String time = getValue(cell).toString();
									String[] strArr = time.split("\\-");
									if (strArr.length == 3) {
										courseCvommond.setSpeakDateStr(sf3.format(sf3.parse(getValue(cell).toString())));
									} else{
										importFlag=false;
										reason="日期填写不正确";
										courseCvommond.setReason(reason);
										courseCvommond.setImportFlag(importFlag);
										return courseCvommond;
									}
								}
							} else {
								importFlag=false;
								reason="日期填写不正确";
								courseCvommond.setReason(reason);
								courseCvommond.setImportFlag(importFlag);
								return courseCvommond;
							}
						}catch (Exception e) {
							importFlag=false;
							reason="日期填写不正确";
							courseCvommond.setReason(reason);
							courseCvommond.setImportFlag(importFlag);
							return courseCvommond;
						}
						break;
					case 1 ://时间
						if(PropertyUtil.objectNotEmpty(getValue(cell).toString())){
							List<BaseData> codeList = validDataNameIsExist(getValue(cell).toString());
							if (!PropertyUtil.objectNotEmpty(codeList)){
								importFlag=false;
								reason="时间填写不正确";
								courseCvommond.setReason(reason);
								courseCvommond.setImportFlag(importFlag);
								return courseCvommond;
								
							}else{
								courseCvommond.setSpeakTime(codeList.get(0).getDataCode());
							}
						}else{
							courseCvommond.setSpeakTime(null);
						}
						break;
					case 2 ://课程名
						courseCvommond.setCourseName(getValue(cell).toString());
						break;
					case 3 ://课程类型
						if(PropertyUtil.objectNotEmpty(getValue(cell).toString())){
							List<BaseData> codeList = validDataNameIsExist(getValue(cell).toString());
							if (!PropertyUtil.objectNotEmpty(codeList)){
								importFlag=false;
								reason="课程类型填写不正确";
								courseCvommond.setReason(reason);
								courseCvommond.setImportFlag(importFlag);
								return courseCvommond;
								
							}else{
								courseCvommond.setSpeakway(codeList.get(0).getDataCode());
							}
						}else{
							courseCvommond.setSpeakway(null);
						}
						break;
					case 4 ://授课教师
						courseCvommond.setSpeaker(getValue(cell).toString());
						break;
					case 5 ://教师单位
						courseCvommond.setSpeakdept(getValue(cell).toString());
						break;
					case 6 ://教师职务职称
						courseCvommond.setSpeakDuty(getValue(cell).toString());
						break;
				}
			}
		}
		if (empty){
			courseCvommond = null;	
		}
		else{
			courseCvommond.setImportFlag(importFlag);
		}
		return courseCvommond;
	}
	/**
	 * 根据单元格数据类型返回相应数据
	 * @param cell
	 * @return
	 */
	private Object getValue(Cell cell) {
		switch (cell.getCellType()) {
		case Cell.CELL_TYPE_STRING:
			return (cell.getRichStringCellValue().getString());
		case Cell.CELL_TYPE_NUMERIC:
			if (DateUtil.isCellDateFormatted(cell)) {
				return (cell.getDateCellValue());
			} else {
				BigDecimal bg = new BigDecimal(cell.getNumericCellValue());
				return bg.toPlainString();
			}
		case Cell.CELL_TYPE_BOOLEAN:
			return (cell.getBooleanCellValue());
		case Cell.CELL_TYPE_FORMULA:
			return (cell.getCellFormula());
		default:
			return "";
		}
	}
	/**
	 * 验证数据字典
	 * @param dataName
	 * @return
	 * @throws Exception
	 */
	public List<BaseData> validDataNameIsExist(String dataName) throws Exception {
		BaseDataCondition baseDataCondition = new BaseDataCondition();
		baseDataCondition.setSearchBaseName(dataName);
		baseDataCondition.setRows(1);
		List<BaseData> list = baseDataManager.listBaseData(baseDataCondition);
		return list;
	}
	
	
	/**
	 * 验证人员信息
	 * @param commond
	 * @return Map<String,Object>     
	 * @author LongJZ
	 * @throws Exception 
	 * @createDate 2015-8-14
	 */
	public ClassCourseValidCommond validateUserInfo(ClassCourseValidCommond courseCvommond) throws Exception {
		Boolean importFlag = true;
		String reason = "";
		if(PropertyUtil.objectNotEmpty(courseCvommond)){
			//课程名称
			if(!PropertyUtil.objectNotEmpty(courseCvommond.getCourseName())){
				
				importFlag=false;
				reason="课程名称为空";
				courseCvommond.setReason(reason);
				courseCvommond.setImportFlag(importFlag);
				return courseCvommond;
			}
			
			if(PropertyUtil.objectNotEmpty(courseCvommond.getCourseName()) && courseCvommond.getCourseName().length()>50){
				importFlag=false;
				reason="课程名称超过50字符";
				courseCvommond.setReason(reason);
				courseCvommond.setImportFlag(importFlag);
				return courseCvommond;
			}
			//课程类型
			if(!PropertyUtil.objectNotEmpty(courseCvommond.getSpeakway())){
				
				importFlag=false;
				reason="课程类型为空";
				courseCvommond.setReason(reason);
				courseCvommond.setImportFlag(importFlag);
				return courseCvommond;
			}
			/*//授课教师
			if(!PropertyUtil.objectNotEmpty(courseCvommond.getSpeaker())){
				
				importFlag=false;
				reason="授课教师为空";
				courseCvommond.setReason(reason);
				courseCvommond.setImportFlag(importFlag);
				return courseCvommond;
			}
						
			//教师单位
			if(!PropertyUtil.objectNotEmpty(courseCvommond.getSpeakdept())){
				
				importFlag=false;
				reason="教师单位为空";
				courseCvommond.setReason(reason);
				courseCvommond.setImportFlag(importFlag);
				return courseCvommond;
			}
						
			//职务职称
			if(!PropertyUtil.objectNotEmpty(courseCvommond.getSpeakDuty())){
				
				importFlag=false;
				reason="职务职称为空";
				courseCvommond.setReason(reason);
				courseCvommond.setImportFlag(importFlag);
				return courseCvommond;
			}*/
		}


		courseCvommond.setImportFlag(importFlag);
		courseCvommond.setReason(reason);
		return courseCvommond;
	}
	/**
	 * 查询班级课程列表
	 * @param commond
	 * @return
	 * @throws Exception
	 * @author RongSL
	 * @date 2016-05-20
	 */
	@Override
	public List<ClassCourseQueryBean> findAssessCourseList(ClassCourseQueryCommond  qCommond) throws Exception{
		return classCourseDao.findAssessCourseList(qCommond);
	}
	
	/**
	 * 删除课程问卷
	 * @param validCommond
	 * @param request
	 * @param response
	 * @param resultState
	 * @throws Exception
	 * @author RongSL
	 * @createDate 2016-5-24
	 */
	@Override
	public void deleteCourseQuestionnaire(ClassCourseValidCommond validCommond){
		classCourseDao.deleteCourseQuestionnaire(validCommond);
	}
}
